<?php
// 后台管理
class UserAction extends PublicAction{

	public function index()
	{
		$model        =  D('Sys_user');
		if(!empty($model)) {
			$this->_list($model,$map);
		}
		$this->display();
	}

	//重置密码
	public function resetPwd()
	{
		$id  =  $_POST['id'];
		$password = $_POST['password'];
		if(empty($password)) {
			$this->error('密码不能为空！');
		}
		$Auth = D('Sys_user');
		$Auth->password	=	md5($password);
		$Auth->id			=	$id;
		$result	=	$Auth->save();
		if(false !== $result) {
			$this->success("密码修改为$password");
		}else {
			$this->error('重置密码失败！');
		}
	}

	function insert()
	{
		$model	=	 D('Sys_user');
		if(false === $model->create()) {
			$this->error($model->getError());
		}
		//保存当前数据对象
		$id = $model->add();
		if($id) { //保存成功
			//成功提示
			$this->success(L('_INSERT_SUCCESS_'));
		}else {
			//失败提示
			$this->error(L('_INSERT_FAIL_'));
		}
	}

	public function add() {
		$this->display();
	}

	function read() {
		$this->edit();
	}

	function edit() {
		$model	=	 D('Sys_user');
		$id     = $_REQUEST['id'];
		$vo	=	$model->getById($id);
		$this->assign('vo',$vo);
		$this->display();
	}

	function update() {
		$model	=	 D('Sys_user');
		if(false === $vo = $model->create()) {
			$this->error($model->getError());
		}
		$result	=	$model->save();
		if($result) {
			//成功提示
			$this->success(L('_UPDATE_SUCCESS_'));
		}else {
			//错误提示
			$this->error(L('_UPDATE_FAIL_'));
		}
	}

	/**
     +----------------------------------------------------------
     * 默认删除操作
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     * @throws ThinkExecption
     +----------------------------------------------------------
     */
	public function delete()
	{
		//删除指定记录
		$model        = D('Sys_user');
		if(!empty($model)) {
			$id         = $_REQUEST['id'];
			if(isset($id)) {
				if($model->delete($id)){
					$this->success(L('_DELETE_SUCCESS_'));
				}else {
					$this->error(L('_DELETE_FAIL_'));
				}
			}else {
				$this->error('非法操作');
			}
		}
	}

	/**
     +----------------------------------------------------------
     * 默认禁用操作
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     * @throws FcsException
     +----------------------------------------------------------
     */
	function forbid()
	{
		$model	=	 D('Sys_user');
		$condition = 'id IN ('.$_GET['id'].')';
		if($model->forbid($condition)){
			$this->assign("message",'状态禁用成功！');
			$this->assign("jumpUrl",$this->getReturnUrl());
		}else {
			$this->assign('error',  '状态禁用失败！');
		}
		$this->forward();
	}

	/**
     +----------------------------------------------------------
     * 默认恢复操作
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     * @throws FcsException
     +----------------------------------------------------------
     */
	function resume()
	{
		//恢复指定记录
		$model	=	 D('Sys_user');
		$condition = 'id IN ('.$_GET['id'].')';
		if($model->resume($condition)){
			$this->assign("message",'状态恢复成功！');
			$this->assign("jumpUrl",$this->getReturnUrl());
		}else {
			$this->assign('error',  '状态恢复失败！');
		}
		$this->forward();
	}


}
?>